part of '../index.dart';

abstract class Debouncer {
  static final _keyToStamp = <dynamic, int>{};
  static var _stamp = 0;

  static void run(dynamic key, Duration duration, Function runnable) {
    late final int callStamp;
    _keyToStamp[key] = callStamp = _stamp++;

    Future.delayed(duration, () {
      if (_keyToStamp[key] == callStamp) {
        _keyToStamp.remove(key);
        runnable();
      }
    });
  }
}
